package com.lebang.controller.sys;

import com.lebang.common.Login;
import com.lebang.entity.sys.AppNotice;
import com.lebang.service.sys.AppNoticeService;
import com.lebangweb.response.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * 描述：任务收退款管理控制层
 *
 * @author HWQ
 * @date Tue May 14 11:18:51 CST 2019
 */
@Controller
@RequestMapping("/appNotice")

public class AppNoticeController {

    @Autowired
    private AppNoticeService appNoticeService;

    @GetMapping("/list")
    @Login
    public String list() {
        return "/appnotice/tbappnotice-list";
    }

    /**
     * 新增修改保存
     **/
    @PostMapping("/edit")
    @ResponseBody
    @Login
    public JsonData edit(AppNotice po) {
        if (po.getId() == null) {
            return appNoticeService.insert(po);
        } else {
            return appNoticeService.update(po);
        }
    }

    /**
     * 新增修改跳转
     **/
    @GetMapping("/edit")
    @Login
    public String edit(@RequestParam(name = "id", required = false) Integer id,
                       Model model) {
        if (!"".equals(id) && null != id) {
            model.addAttribute("item", appNoticeService.selectByPrimaryKey(id));
        } else {
            model.addAttribute("item", new AppNotice());
        }
        model.addAttribute("parent", appNoticeService.selectParent());
        return "/appnotice/app-edit";
    }

}